package com.tensai.study.java.newconcept.typereactiveprogram.reactor.flux;

import cn.hutool.core.util.RandomUtil;
import org.junit.Test;
import reactor.core.publisher.Flux;

/**
 * 懒汉型
 *
 * @author Tensai
 */
public class DeferTest {

	@Test
	public void test() {
		Flux.defer(() -> {
			if (RandomUtil.randomBoolean()) {
				return getFlux();
			} else {
				return Flux.empty();
			}
		}).subscribe(System.out::println);
	}

	private Flux<String> getFlux() {
		return Flux.just("a", "b", "c");
	}
}
